Page({
    data: {
        iphone_x: !1,
        card: [],
        list: [],
        modal: !1,
        page_loading: !0,
        beCard: null,
        dialog: !1,
        newIndex: "0",
        action: [ {
            name: "取消",
            color: "#666666"
        }, {
            name: "确认",
            color: "#446dfd",
            loading: !1
        } ]
    },
    onLoad: function(t) {
        var a = this;
        getApp().api.getStorage({
            key: "goods_card",
            success: function(t) {
                console.log(t), a.setData({
                    list: t.data
                });
            }
        }), getApp().device().indexOf("iphone_x") > -1 && this.setData({
            iphone_x: !0
        }), this.getCard();
    },
    getCard: function() {
        var t = this;
        getApp().request({
            url: getApp().apiUrl.app_admin.card,
            method: "get"
        }).then(function(a) {
            if (getApp().iView.$Toast.hide(), 0 == a.data.code) {
                var e = a.data.data.list;
                t.setData({
                    card: e
                });
            } else getApp().iView.$Toast({
                content: a.data.msg,
                duration: 2,
                type: "warning"
            });
        }).catch(function(t) {
            getApp().iView.$Toast({
                content: t.data.msg,
                duration: 2,
                type: "error"
            });
        });
    },
    toChoose: function() {
        this.setData({
            dialog: !this.data.dialog
        });
    },
    bindChange: function(t) {
        var a = t.detail.value[0];
        this.setData({
            newIndex: a
        });
    },
    toggle: function(t) {
        var a = t.currentTarget.dataset.status;
        if (2 == a) this.setData({
            dialog: !1
        }); else if (1 == a) {
            var e = this.data.card[this.data.newIndex];
            this.setData({
                beCard: e,
                dialog: !1,
                newIndex: 0
            });
        }
    },
    close: function(t) {
        var a = t.currentTarget.dataset.index, e = this.data.list;
        e.splice(a, 1), this.setData({
            list: e
        }), getApp().api.setStorage({
            key: "goods_card",
            data: e
        });
    },
    submit: function() {
        var t = this.data.list;
        null != this.data.beCard ? (t.push(this.data.beCard), this.setData({
            to_add: !1,
            beCard: null,
            list: t
        }), getApp().api.setStorage({
            key: "goods_card",
            data: t
        })) : getApp().iView.$Toast({
            content: "请选择卡券",
            duration: 1,
            type: "error"
        });
    },
    cancel: function() {
        this.setData({
            to_add: !1,
            beCard: null
        });
    },
    add: function() {
        var t = this;
        getApp().request({
            url: getApp().apiUrl.app_admin.card,
            method: "get"
        }).then(function(a) {
            if (getApp().iView.$Toast.hide(), 0 == a.data.code) {
                var e = t.data.list, i = a.data.data.list, n = [];
                i.length > 0 ? (e.forEach(function(a, e) {
                    i.forEach(function(e, o) {
                        a.id == i[o].id && (n.push(a), t.setData({
                            list: n
                        }));
                    });
                }), t.setData({
                    to_add: !0
                })) : getApp().iView.$Toast({
                    content: "暂无可添加卡券",
                    duration: 1,
                    type: "error"
                }), t.setData({
                    card: i
                });
            } else getApp().iView.$Toast({
                content: a.data.msg,
                duration: 2,
                type: "warning"
            });
        });
    },
    onReady: function(t) {
        this.setData({
            page_loading: !1
        });
    },
    onShow: function() {},
    onHide: function() {},
    onUnload: function() {},
    onPullDownRefresh: function() {},
    onReachBottom: function() {},
    onShareAppMessage: function() {}
});